<template>
	<view>
		<!-- <u-button type="primary" text="修改信息" @click="toChange" v-if="user.Roles.indexOf('管理员角色')!=-1 || user.Roles.indexOf('公司领导角色')!=-1
		|| user.Roles.indexOf('部门领导角色')!=-1 || user.Roles.indexOf('分公司副总')!=-1 || user.Roles.indexOf('分管领导')!=-1
		|| user.Roles.indexOf('部门内项目部审批人')!=-1 || maintenanceData.CreatorId == user.Id || user.Roles.indexOf('车辆管理员')!=-1"></u-button> -->
		<flowtool :outid="maintenanceData.Id" flowid="775c5e6e-c7e4-441a-81c2-a242252393d8" :outmodalShow="isCreated" :deptid="carDeptId" :outshowbutton="maintenanceData.Status == '进行中' ? true : false " :dataname="carData.CarNo + '保养或维修申请'" :formstate="maintenanceData"></flowtool>
		<u-collapse ref='coll' :value="['1','2']">
			<u-collapse-item name="1" title="信息" icon="order">
				<u-cell-group>
					<u-cell title="车辆名称" :use-label-slot="true">
						<span slot="label" class="cell-label">{{carData.Name}}</span>
					</u-cell>
					<u-cell title="车牌号" :use-label-slot="true">
						<span slot="label" class="cell-label">{{carData.CarNo || " "}}</span>
					</u-cell>
					<u-cell title="状态" :use-label-slot="true">
						<span slot="label" class="cell-label">{{maintenanceData.Status || " "}}</span>
					</u-cell>
					<u-cell title="保养公司" :use-label-slot="true">
						<span slot="label" class="cell-label">{{maintenanceData.MaintenanceCompany || " "}}</span>
					</u-cell>
					<u-cell title="保养项目" :use-label-slot="true">
						<span slot="label" class="cell-label">{{maintenanceData.MaintenanceItems || " "}}</span>
					</u-cell>
					<u-cell title="是否维修" :use-label-slot="true">
						<span slot="label" class="cell-label">{{maintenanceData.IsRepairs==true ? '是' : '否' || " "}}</span>
					</u-cell>
					<u-cell title="保养费用(元)" :use-label-slot="true">
						<span slot="label" class="cell-label">{{maintenanceData.MaintenanceCosts || " "}}</span>
					</u-cell>
					<u-cell title="此次保养时里程" :use-label-slot="true">
						<span slot="label" class="cell-label">{{maintenanceData.CurrentMileage || " "}}</span>
					</u-cell>
					<u-cell title="保养地址" :use-label-slot="true">
						<span slot="label" class="cell-label">{{maintenanceData.Address || " "}}</span>
					</u-cell>
					<u-cell title="保养时间" :use-label-slot="true">
						<span slot="label" class="cell-label">{{maintenanceData.ManitenanceTime || " "}}</span>
					</u-cell>
					<u-cell title="办理人" :use-label-slot="true">
						<span slot="label" class="cell-label">{{maintenanceData.Agent || " "}}</span>
					</u-cell>
					<u-cell title="备注" :use-label-slot="true">
						<span slot="label" class="cell-label">{{maintenanceData.Remark || " "}}</span>
					</u-cell>
				</u-cell-group>
			</u-collapse-item>
			<u-collapse-item name="2" title="附件照片" icon="https://project.gxrunxiang.com/cdn/image.png">
				<u-album :urls="imagesurls1"></u-album>
			</u-collapse-item>
			<!-- <u-button type="error" :plain="true" v-if="user.Roles.indexOf('管理员角色')!=-1 || user.Roles.indexOf('公司领导角色')!=-1 
			|| user.Roles.indexOf('部门领导角色')!=-1 || user.Roles.indexOf('分公司副总')!=-1 || user.Roles.indexOf('分管领导')!=-1
			|| user.Roles.indexOf('部门内项目部审批人')!=-1 || maintenanceData.CreatorId == user.Id || user.Roles.indexOf('车辆管理员')!=-1" 
			@click="delmodalShow = true">删除</u-button> -->
		</u-collapse>
		<u-toast ref="uToast"></u-toast>
		<!-- <u-modal :show="delmodalShow" title="提示" content='确认删除?' @confirm="del" :showCancelButton="true" confirmText="是"
			cancelText="否" @cancel="delmodalShow = false" :closeOnClickOverlay="true"
			@close="delmodalShow = false"></u-modal> -->
	</view>
</template>
<script>
	import {
		baseUrl
	} from '@/common/config.js'
	import flowtool from "../c_flowtool.vue"
	import {
		mapGetters
	} from 'vuex'
	import {
		getmaintenancelist,
		getfilebyoutid,
		delmaintenance
	} from '@/common/api.js'
	export default {
		components: {
		  flowtool
		},
		data() {
			return {
				maintenanceId: "",
				maintenanceData: [],
				carData: [],
				creatorData: [],
				imagesurls1: [],
				modalShow: false,
				delmodalShow: false,
				user: {},
				isCreated: false,
				carDeptId: ""
			}
		},
		onLoad(option) {
			this.user = JSON.parse(uni.getStorageSync("$userinfo"))
			this.maintenanceId = option.Id
			this.isCreated = option.isCreated
		},
		onShow() {
			this.getlist(this.maintenanceId)
		},
		methods: {
			async getlist(id) {
				let para = {
					Parameters: [],
				}
				para.Parameters.push({
					FieldName: "Id",
					ConditionalType: "Equal",
					FieldValue: id
				})
				await getmaintenancelist(para).then(res => {
					this.maintenanceData = res.data[0]
					this.carData = res.data[0].Car
					this.carDeptId = res.data[0].Car.DeptId
					this.creatorData = res.data[0].Creator
				})
				this.imagesurls1 = []
				getfilebyoutid(this.maintenanceId).then(res => {
					for (var i = 0; i < res.length; i++) {
						if (res[i].MyType == '附件照片') {
							this.imagesurls1.push(`${baseUrl}/SysFile/download?id=${res[i].Id}`)
						}
					}
					setTimeout(() => {
							this.$refs.coll.init()
						},
						1000)
				})
			},
			del() {
				let ids = []
				ids.push(this.maintenanceId)
				delmaintenance(ids).then((res) => {
					if (res == true)
						uni.navigateBack()
				})
			},
			// toChange(){
			// 	uni.navigateTo({
			// 		url: "addmaintenance?Id=" + this.maintenanceId
			// 	})
			// }
		}
	}
</script>
<style>
	.cell-label {
		margin-top: 10px;
		font-size: 14px;
		color: #909193;
	}
</style>